{% extends "shop/base.html" %}
{% load i18n %}
{% load static %}

{% block title %}
    {% trans "Your shopping cart" %}
{% endblock %}

{% block content %}
    <h1>{% trans "Your shopping cart" %}</h1>
    <table class="cart">
        <thead>
            <tr>
                <th>{% trans "Image" %}</th>
                <th>{% trans "Product" %}</th>
                <th>{% trans "Quantity" %}</th>
                <th>{% trans "Remove" %}</th>
                <th>{% trans "Unit price" %}</th>                
                <th>{% trans "Price" %}</th>
            </tr>
        </thead>
        <tbody>
        {% for item in cart %}
            {% with product=item.product %}
            <tr>
                <td>
                    <a href="{{ product.get_absolute_url }}">
                        <img src="{% if product.image %}{{ product.image.url }}{% else %}{% static "img/no_image.png" %}{% endif %}">
                    </a>
                </td>
                <td>{{ product.name }}</td>
                <td>
                    <form action="{% url "cart:cart_add" product.id %}" method="post">
                        {{ item.update_quantity_form.quantity }}
                        {{ item.update_quantity_form.update }}
                        <input type="submit" value="{% trans "Update" %}">
                        {% csrf_token %}
                    </form>
                </td>
                <td><a href="{% url "cart:cart_remove" product.id %}">{% trans "Remove" %}</a></td>
                <td class="num">${{ item.price }}</td>
                <td class="num">${{ item.total_price }}</td>
            </tr>
            {% endwith %}
        {% endfor %}
        
        {% if cart.coupon %}
            <tr class="subtotal">
                <td>{% trans "Subtotal" %}</td>
                <td colspan="4"></td>
                <td class="num">${{ cart.get_total_price }}</td>
            </tr>
            <tr>
                {% blocktrans with code=cart.coupon.code discount=cart.coupon.discount %}
                    <td>"{{ code }}" coupon ({{ discount }}% off)</td>
                {% endblocktrans %}
                <td colspan="4"></td>
                <td class="num neg">- ${{ cart.get_discount|floatformat:"2" }}</td>
            </tr>
        {% endif %}
        <tr class="total">
            <td>{% trans "Total" %}</td>
            <td colspan="4"></td>
            <td class="num">${{ cart.get_total_price_after_discount|floatformat:"2" }}</td>
        </tr>

        </tbody>
    </table>
    {% if recommended_products %}
        <div class="recommendations cart">
            <h3>{% trans "People who bought this also bought" %}</h3>
            {% for p in recommended_products %}
            <div class="item">
                <a href="{{ p.get_absolute_url }}">
                    <img src="{% if p.image %}{{ p.image.url }}{% else %}{% static "img/no_image.png" %}{% endif %}">
                </a>
                <p><a href="{{ p.get_absolute_url }}">{{ p.name }}</a></p>
            </div>
            {% endfor %}
        </div>
    {% endif %}
    <p>
        {% trans "Apply a coupon" %}:
    </p>
    <form action="{% url "coupons:apply" %}" method="post">
        {{ coupon_apply_form }}
        <input type="submit" value="{% trans "Apply" %}">
        {% csrf_token %}
    </form>
    <p class="text-right">
        <a href="{% url "shop:product_list" %}" class="button light">{% trans "Continue shopping" %}</a>
        <a href="{% url "orders:order_create" %}" class="button">{% trans "Checkout" %}</a>
    </p>
    
{% endblock %}
